package server.core;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import java.util.Enumeration;

/*
StandardWrapper类的外观类,封装StandardWrapper类以保证Servlet程序只能访问ServletConfig接口中的方法
用于传递给Servlet类的方法: void init(ServletConfig config) throws ServletException;
*/
/*
2023/2/25 该类内容全部写完,后续直接使用,无需修改
by cyl
 */
public class StandardWrapperFacade implements ServletConfig {
    private ServletConfig config = null;
    public StandardWrapperFacade(ServletConfig config) {
        this.config = config;
    }

    @Override
    public String getServletName() {
        return config.getServletName();
    }

    //返回ServletContext类的外观类
    @Override
    public ServletContext getServletContext() {
        ServletContext context = config.getServletContext();
        if (context != null && context instanceof ApplicationContext)
            context = ((ApplicationContext)context).getFacade();
        return context;
    }

    @Override
    public String getInitParameter(String name) {
        return config.getInitParameter(name);
    }

    @Override
    public Enumeration<String> getInitParameterNames() {
        return config.getInitParameterNames();
    }
}
